<?php
/**
 * Created by PhpStorm.
 * User: Keter
 * Date: 2016/8/12
 * Time: 9:51
 */
class GetDiamondsChange extends ApiRedisBase
{
    public function logic()
    {
        $userInfo = $this->checkUser(true);
        $key = 'UDC:' . $this->uid;
        $roomRedis = $this->redis('room_status');

        $detail = array();
        if ($roomRedis->exists($key)) {
            $detail = $roomRedis->lrange($key, 0, -1);
            if ($detail) {
                foreach ($detail as $k => $row) {
                    $detail[$k] = json_decode($row, JSON_UNESCAPED_UNICODE);
                }
                $delResult = $roomRedis->del($key);
                if (!$delResult) {
                    $this->logWarning('failed_del_action', $key);
                }
            }
        }

        $result = array(
            'diamond' => $userInfo['diamond'],
            'detail' => $detail
        );

        $this->returnData('suc_action', $this->formatNumber($result));
    }
}